 
$(function(){
  var currentPosition = 0;
  var slideWidth = 940;
  var slides = $('.img_box');
  var numberOfSlides = slides.length;

   $('#galleryContainer').css('overflow', 'hidden');

   slides
    .wrapAll('<div id="slideInner"></div>')
 	.css({
      'float' : 'left',
      'width' : slideWidth
    });

   $('#slideInner').css('width', slideWidth * numberOfSlides);

   $('#gallery')
    .prepend('<span class="control" id="leftControl">Prev</span>')
    .append('<span class="control" id="rightControl">Next</span>');

   manageControls(currentPosition);

   $('.control')
    .bind('click', function(){
 	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
    
     manageControls(currentPosition);
     $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
  });

   function manageControls(position){
 	if(position==0){ $('#leftControl').hide() } else{ $('#leftControl').show() }
     if(position==numberOfSlides-1){ $('#rightControl').hide() } else{ $('#rightControl').show() }
  }	
});
 
 